<template>
  <div>
<!-- 面包屑导航 -->
<el-breadcrumb separator="/">
      <el-breadcrumb-item>电影管理</el-breadcrumb-item>
      <el-breadcrumb-item>电影列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider></el-divider>

    <!-- 搜索表单 -->
    <el-form @submit.native.prevent :inline="true" class="demo-form-inline">
      <el-form-item label="电影名称">
        <el-input 
          @keyup.native.enter="search"
          v-model="name" 
          placeholder="请输入关键字"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
      </el-form-item>
    </el-form>
    <el-divider content-position="left">电影列表</el-divider>

    <!-- 电影列表 -->
    <el-table :data="movieData.result">
        <el-table-column label="电影封面" width="120px" align="center">
          <template slot-scope="scope">
            <img :src="scope.row.cover" width="60px">
          </template>
        </el-table-column>
        <el-table-column label="电影名称"  prop="title"></el-table-column>
        <el-table-column label="主演"  prop="star_actor"></el-table-column>
        <el-table-column label="上映时间" width="120px"  prop="showingon"></el-table-column>
        <el-table-column label="时长"  width="80px" prop="duration"></el-table-column>
        <el-table-column label="所属类别"  prop="type"></el-table-column>
        <el-table-column label="操作"  width="250px">
          <el-button type="success" icon="el-icon-check" circle></el-button>
         <el-button type="info" icon="el-icon-message" circle></el-button>
         <el-button type="warning" icon="el-icon-star-off" circle></el-button>
         <el-button type="danger" icon="el-icon-delete" circle></el-button>

        </el-table-column>
    </el-table>
    
    <!-- 分页器 -->
    <el-pagination 
        style="margin:10px;"
        background
        :total="movieData.total" 
        :page-size="movieData.pagesize" 
        :current-page="movieData.page"
        layout="->, total, prev, pager, next, jumper"
        @current-change="changeCurrentPage"
        >
    </el-pagination>
  </div>
</template>

<script>
import httpApi from '@/http';
  export default {
    data() {
      return {
        name: '',  //保存查询关键字
        movieData:{ //保存电影数据
          page:0,   //当前页码
          pagesize:0,  //每页多少条
          total:0,  //总条目数
          result:[]  //电影列表
        }
      }
    },
    methods: {
      search() {
        
      },

      //改变当前页 分页器当前页码改变时,传入当前页码
      changeCurrentPage(page){
        console.log(page)
        this.movieData.page = page //修改当前页
        this.queryMovies() //重新加载当前电影列表
      },

      //查询电影列表,根据当前页码,发送请求,加载电影列表数据
      queryMovies(){
        let params = {
          page:this.movieData.page,
          pagesize:this.movieData.pagesize}

          httpApi.movieApi.queryAll(params).then(res=>{
          console.log('加载首页电影列表数据',res)
          this.movieData = res.data.data
        })
      },

      // 初始化化电影首页数据
      init(){
        let params = {page:1,pagesize:2}
        httpApi.movieApi.queryAll(params).then(res=>{
          console.log('加载首页电影列表数据',res)
          
          this.movieData = res.data.data
        })

      }
    },

    // 钩子函数,组件挂载完毕后执行
    mounted(){
      //初始化电影列表首页数据
      this.init()
    },
  }
</script>

<style lang="scss" scoped>

</style>